
/* Thanks go out to Steven Haines for providing on the web the base of
 * this tail program.
 *
 * Minor Modifications were made for additional functionality.
 *
 * Original source can be found at:
 *
 * http://www.informit.com/guides/content.aspx?g=java&seqNum=226
 */

package com.dmdba.util.tail;
public class Tail implements LogFileTailerListener
{
  private LogFileTailer tailer;
  private String[] args;

  public Tail( String[] args )
  {
    this.args = args;
    tailer = new LogFileTailer( args, 1000, false );
    tailer.addLogFileTailerListener( this );
    tailer.start();
  }

  public void printLogLine(String line)
    {
      System.out.println( line );
  }
  public void newLogFileLine(String line)
  {
      if(args.length < 2){
          printLogLine( line );
      }
      if(args.length > 9 && line.toLowerCase().contains(args[9].toLowerCase()))
      {
            printLogLine( line );
      }
      if(args.length > 8 && line.toLowerCase().contains(args[8].toLowerCase()))
      {
            printLogLine( line );
      }
      if(args.length > 7 && line.toLowerCase().contains(args[7].toLowerCase()))
      {
            printLogLine( line );
      }
      if(args.length > 6 && line.toLowerCase().contains(args[6].toLowerCase()))
      {
           printLogLine( line );
      }
      if(args.length > 5 && line.toLowerCase().contains(args[5].toLowerCase()))
      {
            printLogLine( line );
      }
      if(args.length > 4 && line.toLowerCase().contains(args[4].toLowerCase()))
      {
            printLogLine( line );
      }
      if(args.length > 3 && line.toLowerCase().contains(args[3].toLowerCase()))
      {
            printLogLine( line );
      }
      if(args.length > 2 && line.toLowerCase().contains(args[2].toLowerCase()))
      {
            printLogLine( line );
      }
      else if(args.length > 1 && line.toLowerCase().contains(args[1].toLowerCase()))
      {
            printLogLine( line );
      }

  }

  public static void main( String[] args )
  {
    if( args.length < 1 )
    {
      System.out.println( "Usage: Tail <filename>" );
      System.exit( 0 );
    }
    Tail tail = new Tail( args );
  }
}